unit BalcaoDevolucao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DMGeral, SqlExpr, Provider, DB, DBClient, DBLocal, DBLocalS, Grids,
  DBGrids, ZAbstractRODataset, ZAbstractDataset, ZDataset, ZSqlUpdate,
  StdCtrls, Buttons;

type
  TfrmBalcaoDevolucao = class(TForm)
    DBGrid1: TDBGrid;
    DS_Saida: TDataSource;
    SQLC_Saida: TSQLClientDataSet;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    SQLC_SaidaSAI_SEQITEM: TSmallintField;
    SQLC_SaidaSAI_IDFITEM: TIntegerField;
    SQLC_SaidaSAI_PREVEN: TFMTBCDField;
    SQLC_SaidaSAI_QUANTI: TFMTBCDField;
    SQLC_SaidaSAI_QTDDEVOLUCAO: TSmallintField;
    SQLC_SaidaSAI_PRETAB: TFMTBCDField;
    SQLC_SaidaDescricao: TStringField;
    procedure SQLC_SaidaBeforePost(DataSet: TDataSet);
    procedure FormShow(Sender: TObject);
    procedure SQLC_SaidaSAI_QTDDEVOLUCAOValidate(Sender: TField);
  private
    { Private declarations }
  public
    { Public declarations }
    Registros: TStrings;
//    cont: integer;
  end;

var
  frmBalcaoDevolucao: TfrmBalcaoDevolucao;

implementation

{$R *.dfm}

procedure TfrmBalcaoDevolucao.SQLC_SaidaBeforePost(DataSet: TDataSet);
begin
  if Registros.IndexOf(IntToStr(DataSet.RecNo)) = -1  then
    Registros.Add(IntToStr(DataSet.RecNo));
end;

procedure TfrmBalcaoDevolucao.FormShow(Sender: TObject);
begin
  Registros := TStringList.Create;
  with SQLC_Saida do begin
    if RecordCount > 0 then begin
      First;
      while not eof do begin
        DtmGeral.TClasseGeral.ExecutaQuery('select esp_codigo as Codigo, '+
        'esp_descri as Descricao from ESTOQUE_PRODUTO where esp_idfcod='+
        FieldbyName('SAI_IDFITEM').AsString, DtMGeral.sqlq_geral );
        Edit;
        if not DtmGeral.sqlq_geral.Eof then
          FieldbyName('Descricao').AsString := DtMGeral.sqlq_geral.FieldbyName('Descricao').AsString;
        Next;
      end;
    end;
  end;
end;

procedure TfrmBalcaoDevolucao.SQLC_SaidaSAI_QTDDEVOLUCAOValidate(
  Sender: TField);
begin
  if (Sender.AsFloat > SQLC_SaidaSAI_QUANTI.AsFloat) then
    raise Exception.Create('Valor deve ser menor que a quantidade comprada');
end;

end.
